package com.fushenlan.epidemicControl.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 注册jwt拦截器
 */
@Configuration
public class JwtInterceptorConfig implements WebMvcConfigurer {

    @Autowired
    JwtTokenInterceptor jwtTokenInterceptor;

    /**
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtTokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/swagger-ui.html/**", "/swagger-resources/**", "/webjars/**", "/v2/**")
                .excludePathPatterns("/wx/getThirdSession/**")
                .excludePathPatterns("/wx/authLogin")
                .excludePathPatterns("/wx/getUserPhoneNumber/**")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/area/getSubAreaByIdAndDeep")
                .excludePathPatterns("/area/getNeighborhood")
                .excludePathPatterns("/area/getBuildById")
                .excludePathPatterns("/cache/clearByKey")
                .excludePathPatterns("/user/getVerificationCode/**");
        WebMvcConfigurer.super.addInterceptors(registry);

    }

    /**
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
